#=======================================================================
# R scripts for testing Affinity propagation clustering
#=======================================================================
# Apache License v.2
# T.S.Yo 2008.11.17
#=======================================================================
#=======================================================================
#  Ref:
#   http://www.psi.toronto.edu/affinitypropagation/
#=======================================================================
#-----------------------------------------------
# Load test data
pref <- array(rep(-15.561256,25),dim=25)
p<-array(c(-2.341500,3.696800,
    -1.109200, 3.111700,
    -1.566900, 1.835100,
    -2.658500, 0.664900,
    -4.031700, 2.845700,
    -3.081000, 2.101100,
    2.588000, 1.781900,
    3.292300, 3.058500,
    4.031700, 1.622300,
    3.081000, -0.611700,
    0.264100, 0.398900,
    1.320400, 2.207400,
    0.193700,3.643600,
    1.954200, -0.505300,
    1.637300, 1.409600,
    -0.123200, -1.516000,
    -1.355600, -3.058500,
    0.017600, -4.016000,
    1.003500, -3.590400,
    0.017600, -2.420200,
    -1.531700, -0.930900,
    -1.144400, 0.505300,
    0.616200, -1.516000,
    1.707700, -2.207400,
    2.095100, 3.430900),dim=c(25,2))
sim <- array(c(
0,-1.860905,-4.065932,-9.292907,-3.581147,-3.093119,-27.966812,-32.147129,-44.921228,-47.966678,-17.665296,-15.627824,-6.430069,-36.110683,-21.062133,-32.094139,-46.606077,-65.052637,-64.292309,-42.983042,-22.071383,-11.618721,-35.921273,-51.255598,-19.754122,
-1.860905,0,-1.839197,-8.387161,-8.611762,-4.909308,-15.437656,-19.376032,-28.647165,-31.421484,-9.245237,-6.720715,-1.980466,-22.467109,-10.440407,-22.387803,-38.132081,-52.073786,-49.381646,-31.871596,-16.521121,-6.79456,-24.392612,-36.22775,-10.369427,
-4.065932,-1.839197,0,-2.560959,-7.096551,-2.363255,-17.266024,-25.108532,-31.389606,-27.589805,-5.415231,-8.475109,-6.370385,-17.875617,-10.447948,-13.314141,-23.991969,-36.746011,-36.043006,-20.618218,-7.651995,-1.946874,-15.995797,-27.064811,-15.956822,
-9.292907,-8.387161,-2.560959,0,-6.641567,-2.241177,-28.773451,-41.141342,-45.675391,-34.571568,-8.612347,-18.210951,-17.007699,-22.646369,-19.008476,-11.184071,-15.561256,-29.072336,-31.517822,-16.679353,-3.816256,-2.317971,-15.479985,-27.31381,-30.247469,
-3.581147,-8.611762,-7.096551,-6.641567,0,-1.45826,-44.952099,-53.68626,-66.515127,-62.544116,-24.440728,-29.052401,-18.49065,-47.0602,-34.199944,-34.300799,-42.021089,-63.479757,-66.776622,-44.126533,-20.512708,-13.813973,-40.627401,-58.474532,-37.880137,
-3.093119,-4.909308,-2.363255,-2.241177,-1.45826,0,-32.23945,-41.535568,-50.819751,-45.329528,-14.087179,-19.383622,-13.102966,-32.14656,-22.740527,-21.831993,-29.598477,-47.020234,-49.076312,-30.043476,-11.593354,-6.296997,-26.7527,-41.49482,-28.560379,
-27.966812,-15.437656,-17.266024,-28.773451,-44.952099,-32.23945,0,-2.125746,-2.109742,-5.97237,-7.3132,-1.78786,-9.198599,-5.632986,-1.042438,-18.22675,-38.981453,-40.222601,-31.372248,-24.264601,-24.331212,-15.560517,-14.76414,-16.689443,-2.962151,
-32.147129,-19.376032,-25.108532,-41.141342,-53.68626,-41.535568,-2.125746,0,-2.609383,-13.515016,-16.243467,-4.612761,-9.943664,-14.491182,-5.457896,-32.591691,-59.020663,-60.77221,-49.446477,-40.739814,-39.186288,-26.203137,-28.087561,-30.24066,-1.57197,
-44.921228,-28.647165,-31.389606,-45.675391,-66.515127,-50.819751,-2.109742,-2.609383,0,-5.894586,-15.691517,-7.69349,-18.815898,-8.842688,-5.778393,-27.112121,-50.93289,-47.903426,-36.342237,-32.454805,-37.47025,-28.0397,-21.514567,-20.067578,-7.021454,
-47.966679,-31.421484,-27.589805,-34.571568,-62.544116,-45.329528,-5.97237,-13.515016,-5.894586,0,-8.956238,-11.047037,-26.444079,-1.280999,-6.169923,-11.084656,-25.67025,-20.973678,-13.18866,-12.655092,-21.37889,-19.101694,-6.892998,-4.432211,-17.314614,
-17.665296,-9.245237,-5.415231,-8.612347,-24.440728,-14.087179,-7.3132,-16.243467,-15.691517,-8.956238,0,-4.386442,-10.533034,-3.674016,-2.907193,-3.816843,-14.577043,-19.552104,-16.461227,-8.008087,-4.993266,-1.995193,-3.790816,-8.876781,-12.545585,
-15.627824,-6.720715,-8.475109,-18.210951,-29.052401,-19.383622,-1.78786,-4.612761,-7.69349,-11.047037,-4.386442,0,-3.332123,-7.760444,-0.73691,-15.947689,-34.890679,-40.427995,-33.71491,-23.11197,-17.983401,-8.972383,-14.359605,-19.64046,-2.097112,
-6.430069,-1.980466,-6.370385,-17.007699,-18.49065,-13.102966,-9.198599,-9.943664,-18.815898,-26.444079,-10.533034,-3.332123,0,-20.312731,-7.074737,-26.721898,-47.318475,-58.700483,-52.986532,-36.800682,-23.903055,-11.639438,-26.799978,-36.526397,-3.660563,
-36.110683,-22.467109,-17.875617,-22.646369,-47.0602,-32.14656,-5.632986,-14.491182,-8.842688,-1.280999,-3.674016,-7.760444,-20.312731,0,-3.767268,-5.337105,-17.473606,-16.075434,-10.421672,-7.417262,-12.332634,-10.622634,-2.811758,-2.957907,-15.513523,
-21.062133,-10.440407,-10.447948,-19.008476,-34.199944,-22.740527,-1.042438,-5.457896,-5.778393,-6.169923,-2.907193,-0.73691,-7.074737,-3.767268,0,-11.658496,-28.921368,-32.060563,-25.401702,-17.290796,-15.520501,-8.555613,-9.601781,-13.087645,-4.295235,
-32.094139,-22.387803,-13.314141,-11.184071,-34.300799,-21.831993,-18.22675,-32.59169,-27.112121,-11.084656,-3.816843,-15.947689,-26.721898,-5.337105,-11.658496,0,-3.898116,-6.269825,-5.572588,-0.837402,-2.326214,-5.128503,-0.546712,-3.830229,-29.392674,
-46.606077,-38.132081,-23.991969,-15.561256,-42.021089,-29.598477,-38.981453,-59.020663,-50.93289,-25.67025,-14.577043,-34.890679,-47.318475,-17.473606,-28.921368,-3.898116,0,-2.802484,-5.84827,-2.293105,-4.557693,-12.745276,-6.267301,-10.108178,-54.019643,
-65.052637,-52.073786,-36.746011,-29.072336,-63.479757,-47.020234,-40.222601,-60.77221,-47.903426,-20.973678,-19.552104,-40.427995,-58.700483,-16.075434,-32.060563,-6.269825,-2.802484,0,-1.153134,-2.546578,-11.918172,-21.792398,-6.608322,-6.127472,-59.772326,
-64.292309,-49.381646,-36.043006,-31.517822,-66.776622,-49.076312,-31.372248,-49.446477,-36.342237,-13.18866,-16.461227,-33.71491,-52.986532,-10.421673,-25.401702,-5.572588,-5.84827,-1.153134,0,-2.341367,-13.500179,-21.388233,-4.453137,-2.408587,-50.490244,
-42.983042,-31.871596,-20.618218,-16.679353,-44.126533,-30.043476,-24.264601,-40.739814,-32.454805,-12.655092,-8.008087,-23.11197,-36.800682,-7.417262,-17.290796,-0.837402,-2.293105,-2.546578,-2.341367,0,-4.618345,-9.908794,-1.1759,-2.901722,-38.551377,
-22.071383,-16.521121,-7.651995,-3.816256,-20.512708,-11.593354,-24.331212,-39.186288,-37.47025,-21.37889,-4.993266,-17.983401,-23.903055,-12.332634,-15.520501,-2.326214,-4.557693,-11.918173,-13.500179,-4.618345,0,-2.212672,-4.955816,-12.123165,-32.178977,
-11.618721,-6.79456,-1.946874,-2.317971,-13.813973,-6.296997,-15.560517,-26.203137,-28.0397,-19.101694,-1.995193,-8.972383,-11.639438,-10.622634,-8.555613,-5.128503,-12.745276,-21.792398,-21.388233,-9.908794,-2.212672,0,-7.185366,-15.493216,-19.053496,
-35.921273,-24.392612,-15.995797,-15.479985,-40.627401,-26.7527,-14.76414,-28.087561,-21.514567,-6.892998,-3.790816,-14.359605,-26.799978,-2.811758,-9.601781,-0.546712,-6.267301,-6.608322,-4.453137,-1.1759,-4.955816,-7.185366,0,-1.669406,-26.658965,
-51.255598,-36.22775,-27.064811,-27.31381,-58.474532,-41.49482,-16.689443,-30.24066,-20.067578,-4.432211,-8.876781,-19.64046,-36.526397,-2.957907,-13.087645,-3.830229,-10.108178,-6.127472,-2.408587,-2.901722,-12.123165,-15.493216,-1.669406,0,-31.940506,
-19.754122,-10.369427,-15.956822,-30.247469,-37.880137,-28.560379,-2.962151,-1.57197,-7.021454,-17.314614,-12.545585,-2.097112,-3.660563,-15.513523,-4.295235,-29.392674,-54.019643,-59.772326,-50.490244,-38.551377,-32.178977,-19.053496,-26.658965,-31.940506,0
),dim=c(25,25))
#-----------------------------------------------
# Source functions for testing
source("../machine.learning/ap.clustering/apclustering.r")
apclustering(sim,pref)

